package com.project.frba.bi.loading;

import com.project.frba.bi.BiUtil;
import com.project.frba.bi.descriptor.Dimension;
import com.project.frba.bi.descriptor.Property;

public class DimensionTableBuilder {

	private Dimension dimension;
	private String statement;
	
	public DimensionTableBuilder(Dimension dimension){
		this.dimension = dimension;
	}
	
	public void buildStatement(){
		StringBuffer statementBuffer = new StringBuffer();
		statementBuffer.append("CREATE TABLE " + dimension.getDescriptor().getDescriptorName() + dimension.getName() + "dimension( ");
		statementBuffer.append("id BIGINT(20) DEFAULT NULL AUTO_INCREMENT, ");
		for (Property property : this.dimension.getProperties()) {
			statementBuffer.append(property.getName() + " " + BiUtil.getDatabaseType(property.getType()) + ", ");
		}
		statementBuffer.append("PRIMARY KEY (id)) ENGINE = InnoDB;");
		this.statement = statementBuffer.toString();
	}
	
	public String getCreateDimensionTableStatement(){
		return this.statement;
	}
	
	public String getDropTableStatement() {
		return "DROP TABLE IF EXISTS " + dimension.getDescriptor().getDescriptorName() + dimension.getName() + "dimension;";
	}

}
